import pytest
import requests


@pytest.fixture()
def login(request):
    config = request.param
    url = config['login']['url']
    headers = {
        "Content-Type": "application/json",
    }
    data = {
        "username": config['user']['username'],
        "password": config['user']['password'],
    }

    response = requests.post(url, headers=headers, json=data)
    if response.status_code == 200:
        content = response.json()
        token = content.get("data").get('Authorization')
        return response.status_code, token
    else:
        return response.status_code, None
